package huoye.shops.huoye.operation.adapter;

import android.content.Context;
import android.graphics.Color;
import android.graphics.Paint;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.codeideology.android.widget.recycler.RecyclerViewAdapter;

import java.math.BigDecimal;

import butterknife.BindView;
import huoye.shops.R;
import huoye.shops.base.APIUrls;
import huoye.shops.huoye.operation.model.SellOrder;
import huoye.shops.huoye.operation.model.ShopPrizeList;
import huoye.shops.huoye.operation.model.ShopProductList;
import huoye.shops.utils.StockUtils;
import huoye.shops.widget.RoundImageView;

import static huoye.shops.huoye.operation.fragment.ManageProductFragment.TYPE_MANAGE_PRODUCT_ALL;


/**
 * Created by uesr on 2018/8/10.
 */

public class ManageShopAdapter extends RecyclerViewAdapter<ManageShopAdapter.ViewHolder, ShopProductList> {


    private int mType;
    public ManageShopAdapter(Context context,int type) {
        super(context, R.layout.item_manage_shop);
        this.mType = type;
    }

    @Override
    protected ViewHolder initViewHolder(View view, int i) {

        return new ViewHolder(view);
    }

    @Override
    protected void bindView(ViewHolder holder, ShopProductList shopProductList, int i) {

        //商品管理
        if (getContext() != null) {
            Glide.with(getContext())
                    .load(APIUrls.COMMON_CONFIG.TYPE_COMMON_ALIYUN + shopProductList.getShowImg())
                    .dontAnimate()
                    .placeholder(R.mipmap.ic_wait_logo)
                    .error(R.mipmap.ic_error)
                    .into(holder.rvShop);
        }



        holder.tvName.setText(shopProductList.getTitle());


        if(mType == TYPE_MANAGE_PRODUCT_ALL){
            holder.tvMoneyOriginal.setVisibility(View.GONE);
            holder.tvMoneyDiscount.setText("￥"+shopProductList.getSaleMoney()+"");

        }else {
            holder.tvMoneyOriginal.setVisibility(View.VISIBLE);
            holder.tvMoneyOriginal.setText(shopProductList.getSaleMoney() + "");
            holder.tvMoneyDiscount.setText("￥"+shopProductList.getDisPayMoney());
            ////中间横线
            holder.tvMoneyOriginal.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);
            // 抗锯齿
            holder.tvMoneyOriginal.getPaint().setAntiAlias(true);
        }



        holder.tvNum.setText("库存" + shopProductList.getSaleCount());
        holder.tvStare.setVisibility(View.GONE);


    }


    public class ViewHolder extends RecyclerViewAdapter.ViewHolder {

        @BindView(R.id.item_manage_shop_tv_shop_name)
        TextView tvName;
        @BindView(R.id.item_manage_shop_tv_state)
        TextView tvStare;
        @BindView(R.id.item_manage_shop_tv_money_discount)
        TextView tvMoneyDiscount;
        @BindView(R.id.item_manage_shop_tv_money_original)
        TextView tvMoneyOriginal;
        @BindView(R.id.item_manage_shop_tv_num)
        TextView tvNum;


        @BindView(R.id.item_manage_shop_rv_shop)
        RoundImageView rvShop;


        public ViewHolder(View itemView) {
            super(itemView);
        }
    }


}
